﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ElectrosLtdApplication.Models;
using System.Web.Security;

namespace ElectrosLtdApplication.Controllers
{
    public class AuthenticationController : MenusController
    {
        //
        // GET: /Login/

        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(LoginModel data)
        {
            if (new UsersServ.UsersServiceClient().AuthenticateUser(data.Username, data.Token, data.PIN))
            {
                FormsAuthentication.RedirectFromLoginPage(data.Username, true);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ViewBag.Message = "Incorrect login details";
                return View();
            }
        }

        public ActionResult LogOff()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Index", "Home");
        }
    }
}
